package exam.locadomain.server;

import exam.config.Utils;
import exam.locadomain.Person;
import exam.localdata.ListDataServer;
import exam.localdata.LocalDataServer;
import exam.localdata.LocalPage;
import exam.localdata.MapServer;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author Xiongx
 * @version 1.0
 * @date 2021/3/31 19:02
 * @since JDK 1.8
 */
@Service
public class PersonServer {


   private static final String name="person";

   private  static List<Person> people=new ArrayList<>();

   private static int code=0;

   public  Integer addPerson(Person person){
      String uuid=Utils.getUUID();
      person.setUuid(uuid);
      if(people.size()==0){
         getPerson();
      }
      people.add(person);
      ListDataServer.wirteList(name,people);
      return 200;
   }

   public void getPageListByName(String name,Integer page,Integer pageSize){
      List<Person> personList=getPerson();
      personList.stream().forEach(e->{
         System.out.println(e);
      });
      List<Person> personList1=personList.stream().filter(e->e.getName().contains(name)).collect(Collectors.toList());
      personList1.stream().forEach(e->{
         System.out.println(e);
      });
      ListDataServer.getLoclaPage(page,pageSize,personList1);
   }

   public static void main(String[] args) {

      PersonServer personServer=new PersonServer();
     // personServer.addPerson(person);
      personServer.getPageListByName("吴",1,10);

   }

   public List<Person> getPerson(){
      if(people.size()==0){
         people=ListDataServer.getListByName(name);
      }
      return people;
   }




}
